package com.blockmeta.bbs.immodule.greendao;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import com.blankj.utilcode.util.LogUtils;

import com.blockmeta.bbs.businesslibrary.util.AccountHelper;
import com.blockmeta.bbs.immodule.bean.Params;
import com.blockmeta.bbs.immodule.bean.sort.DateComparator;
import com.blockmeta.bbs.immodule.bean.sort.StickComparator;
import com.blockmeta.bbs.immodule.dao.ChatMessage;
import com.blockmeta.bbs.immodule.dao.IMUserEntity;
import com.blockmeta.bbs.immodule.dao.Todo;
import com.blockmeta.bbs.immodule.greendao.db.ChatMessageDao;
import com.blockmeta.bbs.immodule.greendao.db.DaoMaster;
import com.blockmeta.bbs.immodule.greendao.db.DaoSession;
import com.blockmeta.bbs.immodule.greendao.db.IMUserEntityDao;
import com.blockmeta.bbs.immodule.greendao.db.TodoDao;
import com.github.yuweiguocn.library.greendao.MigrationHelper;

import org.greenrobot.greendao.identityscope.IdentityScopeType;
import org.greenrobot.greendao.query.QueryBuilder;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by author on 2019/2/13.
 * <p>
 * 原则：保持数据的唯一性！
 * 需要重构，按dao分成多个repository
 */

public class DBHelper {

    private static DBHelper mDBHelper;
    private DaoMaster.DevOpenHelper helper;
    private SQLiteDatabase db;
    private DaoMaster daoMaster;
    private DaoSession daoSession;
    private IMUserEntity mUnique;

    private DBHelper(Context context) {
//        helper = new DaoMaster.DevOpenHelper(context, "im-db", null);

        MigrationHelper.DEBUG = true; //如果你想查看日志信息，请将DEBUG设置为true
        AccountUpdateOpenHelper helper = new AccountUpdateOpenHelper(context, "im-db", null);
        db = helper.getWritableDatabase();
        daoMaster = new DaoMaster(db);
        daoSession = daoMaster.newSession(IdentityScopeType.None);
        QueryBuilder.LOG_SQL = true;
        QueryBuilder.LOG_VALUES = true;
    }

    public static DBHelper getInstance(Context context) {
        if (mDBHelper != null) {
            return mDBHelper;
        } else {
            mDBHelper = new DBHelper(context);
            return mDBHelper;
        }
    }

    public DaoSession getDaoSession(){
        return daoSession;
    }

    public SQLiteDatabase getDb(){
        return db;
    }














}
